package com.xuecheng.manage_course.service;

import com.xuecheng.framework.domain.course.ext.CategoryNode;
import com.xuecheng.manage_course.dao.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class CategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    public List<CategoryNode> selectCategoryList(){
        List<CategoryNode> categoryNodeList = categoryMapper.selectCategoryList();
        // 移除只有1级分类的选项，方便测试
        Iterator<CategoryNode> categoryNodeIterator = categoryNodeList.iterator();
        while (categoryNodeIterator.hasNext()){
            CategoryNode next = categoryNodeIterator.next();
            if (next.getChildren().isEmpty()){
                categoryNodeIterator.remove();
            }
        }
        return categoryNodeList;
    }
}
